/*
 * Copyright (c) 2015-2018 Sfkj Science And Technology Co.,Ltd.
 * All Rights Reserved.
 * This software is the confidential and proprietary information of
 * Sfkj Science And Technology Co.,Ltd.
 * ("Confidential Information").You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sfkj.
 */
package com.sfkj.walk.web;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.Objects;

import static com.sfkj.walk.axon.web.WebContants.MY_PREFIX;

@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
public class HomeController {

    @GetMapping("/health")
    public Map<String, String> health() {
        return ImmutableMap.of("status", "UP");
    }

    @GetMapping("/")
    public Map<String, Object> welcome(HttpSession session, Authentication authentication) {
        Map<String, Object> result = Maps.newHashMap();
        result.put("sessionId", session.getId());
        result.put("principal", Objects.isNull(authentication) ? null : authentication.getPrincipal());
        return result;
    }

    @GetMapping(MY_PREFIX + "/test")
    public Map<String, Object> myInfo(HttpSession session, Authentication authentication) {
        Map<String, Object> result = Maps.newHashMap();
        result.put("sessionId", session.getId());
        result.put("principal", authentication.getPrincipal());
        return result;
    }

}
